package com.zatech.cgnci.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zatech.cgnci.project.base.utils.ConvertUtils;
import com.zatech.cgnci.project.base.utils.VerifyUtils;
import com.zatech.cgnci.project.entity.CgnciApprovalInfoDO;
import com.zatech.cgnci.project.entity.CgnciApprovalRecordDO;
import com.zatech.cgnci.project.mapper.CgnciApprovalInfoMapper;
import com.zatech.cgnci.project.mapper.CgnciApprovalRecordMapper;
import com.zatech.cgnci.project.service.CgnciApprovalRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zatech.cgnci.project.vo.ApprovalRecordVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 审批记录表 服务实现类
 * </p>
 *
 * @author Generator
 * @since 2024-12-17
 */
@Service
public class CgnciApprovalRecordServiceImpl extends ServiceImpl<CgnciApprovalRecordMapper, CgnciApprovalRecordDO> implements CgnciApprovalRecordService {

    @Resource
    CgnciApprovalInfoMapper approvalInfoMapper;
    @Override
    public ApprovalRecordVO getPreviousApprovalRecord(Long insuranceId) {
        List<CgnciApprovalRecordDO> approvalRecordDOList = this.baseMapper.selectList(new LambdaQueryWrapper<CgnciApprovalRecordDO>().eq(CgnciApprovalRecordDO::getFormId, insuranceId));
        List<ApprovalRecordVO> logs = ConvertUtils.convert(approvalRecordDOList, ApprovalRecordVO.class);
        if(VerifyUtils.isEmpty(logs)){
            return new ApprovalRecordVO();
        }else {
            ApprovalRecordVO approvalRecordVO = logs.get(logs.size()-1);
            CgnciApprovalInfoDO cgnciApprovalInfoDO = approvalInfoMapper.selectByApprovalInfoId(approvalRecordVO.getApprovalInfoId());
            approvalRecordVO.setTaskType(cgnciApprovalInfoDO.getTaskType());
            approvalRecordVO.setTaskId(cgnciApprovalInfoDO.getTaskId());
            approvalRecordVO.setGroupID(cgnciApprovalInfoDO.getApprovalConfigGroupId());
            return approvalRecordVO;
        }
    }
}
